From ee32e105e68a24068260f785de34b48934e6e7a3 Mon Sep 17 00:00:00 2001 From: Binary Birch Tree Date: Fri, 2 Sep 2016 21:05:26 -0400 Subject: [PATCH] Generalize error message used by both `cargo package` and `cargo publish`. --- src/cargo/ops/cargo_package.rs | 3 +-- tests/package.rs | 36 +++++++++++++++++++++++++++++++++- tests/publish.rs | 2 +- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 78fde8ed7..dc12e46ff 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -173,8 +173,7 @@ fn check_not_dirty(p: &Package, src: &PathSource) -> CargoResult<()> { Ok(()) } else { bail!("{} dirty files found in the working directory:\n\n{}\n\n\ - to publish despite this, pass `--allow-dirty` to \ - `cargo publish`", + to proceed despite this, pass the `--allow-dirty` flag", dirty.len(), dirty.join("\n")) } } diff --git a/tests/package.rs b/tests/package.rs index d23cc539a..7f3712f37 100644 --- a/tests/package.rs +++ b/tests/package.rs @@ -6,7 +6,7 @@ extern crate hamcrest; extern crate tar; extern crate cargo; -use std::fs::File; +use std::fs::{File, OpenOptions}; use std::io::prelude::*; use std::path::{Path, PathBuf}; @@ -544,3 +544,37 @@ Caused by: [..] ")); } + +#[test] +fn do_not_package_if_repository_is_dirty() { + // Create a Git repository containing a minimal Rust project. + git::repo(&paths::root().join("foo")) + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.0.1" + license = "MIT" + description = "foo" + documentation = "foo" + homepage = "foo" + repository = "foo" + "#) + .file("src/main.rs", "fn main() {}") + .build(); + + // Modify Cargo.toml without committing the change. + let p = project("foo"); + let manifest_path = p.root().join("Cargo.toml"); + let mut manifest = t!(OpenOptions::new().append(true).open(manifest_path)); + t!(writeln!(manifest, "")); + + assert_that(p.cargo("package"), + execs().with_status(101) + .with_stderr("\ +error: 1 dirty files found in the working directory: + +Cargo.toml + +to proceed despite this, pass the `--allow-dirty` flag +")); +} diff --git a/tests/publish.rs b/tests/publish.rs index eb3221b63..b11cb7a47 100644 --- a/tests/publish.rs +++ b/tests/publish.rs @@ -207,7 +207,7 @@ error: 1 dirty files found in the working directory: bar -to publish despite this, pass `--allow-dirty` to `cargo publish` +to proceed despite this, pass the `--allow-dirty` flag ")); } -- 2.30.2